<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript" >
        $(document).ready(function () {

            $("[id='find']").click(function () {
                let flight_date=$("[name='flight_date']").val();
                let city_name=$("[name='city_name']").val();
                let langdingcity=$("[name='landing']").val();

                var ymd=/^\d{4}-\d{2}-\d{2}$/;
                if (!flight_date.match(ymd)){
                    alert("不符合yyyy-mm-dd格式")
                }


                $.get("flys/findall",{"flight_date":flight_date,"city_name":city_name,"langdingcity":langdingcity},function (findflys) {

                    if (findflys.length==0){
                        $("<h3>没有航班信息<h3>").appendTo("h2")
                    }else {
                        $("h2").empty();
                        $("[title='xinxi']").empty();
                        for (let i= 0;i<findflys.length;i++){
                            $("<tr id=u"+findflys[i].id+"  title='xinxi' >" +
                                "<td>"+findflys[i].airline+""+findflys[i].flight_code+""+(findflys[i].type)+"</td>" +
                                "<td>"+findflys[i].take_time+""+findflys[i].landing_time+"</td>" +
                                "<td>"+findflys[i].airport_name+"<br>"+findflys[i].landing+"</td>" +
                                "<td>"+findflys[i].flight_time+"</td>" +
                                "<td>"+findflys[i].stop_airport+"</td>" +
                                "<td>"+findflys[i].reference_price+"<input type='button'  id='qq' value='查询机票' name='"+findflys[i].id+"'></td>" +
                                "</tr> ").appendTo("tbody")
                        }
                    }

                });


            });


            $(document).on("click","[type='button']",function() {
                var uid=$(this).attr("name");

                $.get("flys/findbug",{"id":uid},function (list) {
                    for (var i=0;i<list.length;i++){
                        $("<tr>" +
                            "<td>"+list[i].sell_company+"</td><td>"+list[i].ticket_price+"</td>" +
                            "</tr><br>").insertAfter("[id=u"+uid+"]")
                    }
                });
            });

        });

    </script>
</head>
<body>
<h1>航班查询</h1>
<div>
    <from>
        日期 <input type="text" name="flight_date">
        城市：从 <input type="text" name="city_name">到<input type="text"name="landing">
        <input type="submit" value="搜索" id="find"> <br>
        <table border="1px">
            <tr>
                <td>航空公司/航空机型</td>
                <td>起降时间</td>
                <td>机场</td>
                <td>飞行时间</td>
                <td>经停</td>
                <td>参考报价</td>
            </tr>
        </table>
    </from>
</div>

    <tbody id="bods">

    </tbody>
    <h2></h2>


</body>
</html>